626B - Cards - CodeForces Solution


constructive algorithms dp math *1300

Please click on ads to support us..

Python Code:

n=int(input())
s=input()
if len(set(el for el in s))==1:
    print(s[0])
    
 
elif n==1:
    print(s)
elif n==2:
    if "R" not in s:
        print("R")
    elif "G" not in s:
        print("G")
    else :
        print("B")
else :
    
    a=s.count("R")
    b=s.count("G")
    c=s.count("B")
    p=sum(int(el>=2 ) for el in [a,b,c])
    if a and b and c:
        print('BGR')
    elif p>=2:
        print("BGR")
    else :
        if a>1:
            if b or c:
                print("BG")
            else :
                print("R")
        elif b>1:
            if a or c :
                print("BR")
            else :
                print("G")
        else :
            if a or b:
                print("GR")
            else:
                print("B")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  int a;cin>>a;
  string s;cin>>s;
  int g=0,b=0,r=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  if(r>0&&b>0&&g>0)cout<<"BGR";
  else if((r==0&&b>1&&g>1)||(b==0&&r>1&&g>1)||(g==0&&b>1&&r>1))cout<<"BGR";
  else if(r==0&&b==g&&g==1)cout<<"R";
  else if(b==0&&g==r&&r==1)cout<<"B";
  else if(g==0&&b==r&&r==1)cout<<"G";
  else if(b&&r+g==0)cout<<"B";
  else if(r&&b+g==0)cout<<"R";
  else if(g&&r+b==0)cout<<"G";
    
  else if(g>1&&b+r==1){
    cout<<"BR";
  }
  else if(b>1&&g+r==1){
    cout<<"GR";
  }
  else {
    cout<<"BG";
  }
  
  
  
}


Comments

Submit
0 Comments
More Questions

1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs